<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.BlackPhoneModule.bean.*,com.BlackPhoneModule.dao.*,com.UserModule.dao.TbUserDAO"%>  
<%@ page import="util.*" %>
<%
List<BlackPhoneBean> BlackPhoneList =new ArrayList();
    if(request.getParameter("s")!=null)
    	BlackPhoneList=(ArrayList) session.getAttribute("BlackPhoneList");
    String phone=session.getAttribute("phone").toString();
	  //---------分页
	    int currentPage=1;
	    if(request.getParameter("Page")!=null)
	    {
	    	BlackPhoneList=(ArrayList) session.getAttribute("BlackPhoneList");
	    	currentPage=Integer.parseInt(request.getParameter("Page"));
	    }
	//System.out.println("size==" + SmsTemplateList.size());
%>
<jsp:include page="../head.jsp"></jsp:include>
<body>
<div id="pager">
<jsp:include page="../top.jsp"><jsp:param name="topCurrent" value="4" /></jsp:include>    
<jsp:include page="Left.jsp">
<jsp:param name="um" value="13" /></jsp:include> 
		<section id="container">
        <div id="crumbs">
        	黑名单管理 &raquo; 黑名单列表
        </div>
    <div id="main">
			<div class="tabs">
				<ul class="tabs-nav clearfix">
					<li>
						黑名单列表
					</li>
					<li>
						导入黑名单
					</li>
					<li>
						新增黑名单
					</li>
				</ul>
				<div class="tabs-panel">
			<%
			try{
		 	 String resultSM=session.getAttribute("resultSM").toString();
			 if(!resultSM.equals("")){
				 out.println("<script>alertmess('"+resultSM+"');</script>");
				 session.removeAttribute("resultSM");
			 }
			 }catch(Exception ex){
			 
			 }
		 	%>
				 <form action="" method="post" id="form1" name="form2">
					<table width="100%" class="datalist">
						<thead>
						<tr>
								<th colspan="7" class="tl">
												手机号码
												<input type="text" id="phone" name="phone" maxlength="11" value="<%=phone %>" />
												<input type="button" value="查询" onclick="searcherByphone('../BlackPhoneModuleServlet?method=looksearch')" />&nbsp;&nbsp;
												<input type="button" value="批删" onclick="deleteSmsAllSM('deleteAll','../BlackPhoneModuleServlet?method=deleteAll&looksms=2&phone=<%=phone %>')" />&nbsp;&nbsp;
											    <input type="button" value="导出" onclick="window.location='../upload/export3.xls'" />
											     
								</th>
							</tr>
							<tr>
								<td class="tc">
									<input type="checkbox" title="全选" onClick="check_allSM('deleteAll')"/>
								</td>
								<td>
									序号
								</td>
								<td>
									手机号码
								</td>
									<td>
									创建人
								</td>
								<td>
									创建时间
								</td>
								<td>
									操作
								</td>
							</tr>
							
						</thead>
						<%
						if(BlackPhoneList!=null){
							String[][] exportArray=new String[BlackPhoneList.size()+1][4];
				        	exportArray[0][0]="手机号码";
				        	exportArray[0][1]="创建人";
				        	exportArray[0][2]="创建时间";
				        	for(int rowIndex=1;rowIndex<BlackPhoneList.size()+1;rowIndex++)
				        	{
				        		    BlackPhoneBean bpb=BlackPhoneList.get(rowIndex-1);
				        			exportArray[rowIndex][0]=""+bpb.getPhone();
				        			exportArray[rowIndex][1]=""+((new TbUserDAO().getTbUsersByUserId(bpb.getUserid())).getUserName());
				        			exportArray[rowIndex][2]=""+bpb.getCreateTime().substring(0,19);
				        	}
				        	FileOperate.setExcelSavePath(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
				        	FileOperate.deleteFile(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
				        	FileOperate.writeExcel(exportArray);
							int i=0;  
							//--------------分页
							MyPagination mPage=new MyPagination();
							BlackPhoneList=mPage.getInitPage(BlackPhoneList,currentPage,10);
							if (BlackPhoneList != null && BlackPhoneList.size() > 0) {
											
							for (BlackPhoneBean tbBlackPhoneBean : BlackPhoneList) {
							i++;
						%>
						<tr>
							<td class="tc">
								<input name="deleteAll" id = "deleteAll" type="checkbox" value="<%=tbBlackPhoneBean.getId()%>"/>
							</td>
				  			 <td><%=((10*(currentPage-1))+i) %></td>
							<td><%=tbBlackPhoneBean.getPhone() %></td>
							<td><%=(new TbUserDAO().getTbUsersByUserId(tbBlackPhoneBean.getUserid())).getUserName()%></td>
							<td><%=tbBlackPhoneBean.getCreateTime().substring(0,19)%></td>
							<td class="tc">
							    
								<a title="删除该记录" class="duanyu_del" style="cursor:hand" onClick="deleteOneSM('../BlackPhoneModuleServlet?method=deleteOne&BlackPhoneId=<%=tbBlackPhoneBean.getId() %>')">删除</a>
							</td>
						</tr> 
					   <%
					   }
					   }
					   
					   %>
					   <%=mPage.printCtrl("AddressListModule/BlackPhoneList.jsp",currentPage,"&phone="+phone) %>
						<%}
						else{
											    String[][] exportArray=new String[1][4];
										      	exportArray[0][0]="手机号码";
									        	exportArray[0][1]="创建人";
									        	exportArray[0][2]="创建时间";
									 			FileOperate.setExcelSavePath(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
									        	FileOperate.deleteFile(request.getRealPath("/")+"upload".replace("\\","/")+"/"+"export3.xls");
									        	FileOperate.writeExcel(exportArray);
					        	
											}
						%>
					</table>
				</form>
				</div>
				<div class="tabs-panel">
				    <form id="formimport" name="formimport" enctype="multipart/form-data"  method="post" action="">
                	<table width="100%" class="datalist">
                	<tr>
                	<td class="tc">导入模版：</td>
                	<td>
                	    <a href="./module/blackphoneimport.xls" >点击这里下载导入模板</a>
                	</td>
                	</tr>
                      <tr>
                        <td  class="tc">导入黑名单：</td>
                        <td>
                           <input  type="file" id="daoru" name="daoru" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="insertImport()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function insertImport(){
                        			var fileName = document.getElementById("daoru").value;
                        			var lastFileName = encodeURI(fileName);
                        			lastFileName = encodeURI(lastFileName);
                        			 var file_Name = fileName.split(".")[fileName.split(".").length-1];
                        			if(file_Name=="xls"||file_Name=="XLS")
                        			{
                        			 
                        			 }else
                        			 {
                        			 	alert("上传文件格式不对，请重新导入！");
                        			 	return ;
                        			 }
                        			formimport.action="./BlackPhoneModuleServlet?method=importBlackPhoneSubmit&realImagePath="+lastFileName;
                        			formimport.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>
				<div class="tabs-panel">
				    <form id="formadd" name="formadd"    method="post" action="">
                	<table width="100%" class="datalist">
                      <tr>
                        <td  class="tc">新增黑名单：</td>
                        <td>
                           <input  type="text" id="blackphone" maxlength="11" name="blackphone" value="" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="addblackphone()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function addblackphone(){
                        			var blackphone = document.getElementById("blackphone").value;
                        			if(blackphone.length!=11 || blackphone.length==0)
                        			{
                        				alert("手机号码格式不正确，请重新添加！");
                        				return;
                        			 } 
                        			formadd.action="./BlackPhoneModuleServlet?method=addBlackPhoneSubmit";
                        			formadd.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>
		</div>
	</div>

		
		</section>
		</div>
		  <jsp:include page="../foot.jsp"></jsp:include>
	</body>
</html>
